package acm.pta9;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class 冰岛人 {
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n = sc.nextInt();
        String[][] arr=new String[n][2];
        Graph graph = new Graph();
        for (int i = 0; i < arr.length; i++) {
            arr[i]=new String[]{sc.next(),sc.next()};
        }
        graph.init(arr);
        n = sc.nextInt();
        while (n-- > 0) {
            String name1 = sc.next();
            sc.next();
            String name2 = sc.next();
            sc.next();
            if (!graph.map.containsKey(name1)||!graph.map.containsKey(name2)){
                System.out.println("NA");
                continue;
            }
            if (graph.checkNature(name1,name2)){
                System.out.println("Whatever");
                continue;
            }
            if (graph.isOk(name1,name2)){
                System.out.println("Yes");
            }else {
                System.out.println("No");
            }
        }
    }
    static class Node{
        boolean sex;    //女性true，男性false
        String name;
        String last;    //姓氏
        Node parent;

        @Override
        public String toString() {
            return "Node{" +
                    "name='" + name + '\'' +
                    '}';
        }

        public Node(boolean sex, String name, String last) {
            this.sex = sex;
            this.name = name;
            this.last = last;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node node = (Node) o;
            return Objects.equals(name, node.name);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name);
        }
    }
    static class Graph{
        Map<String,Node> map =new HashMap<>();

        public void init(String[][] arr){
            for (String[] people : arr) {
                map.put(people[0],getNode(people[0],people[1]));
            }
            for (String[] people : arr) {
                Node node = map.get(people[0]);
                node.parent = map.get(node.last);
            }
        }
        public boolean isOk(String a1,String a2){
            Node node1 = map.get(a1);
            Node node2=map.get(a2);
            Set<Node> set1=new HashSet<>();
            Set<Node> set2=new HashSet<>();
            Node curr=node1;
            while (curr!=null){
                set1.add(curr);
                curr=curr.parent;
            }
            curr=node2;
            while (curr!=null){
                set2.add(curr);
                curr=curr.parent;
            }

            int i=4;
            while (node1!=null&&i-->0){
                if (set2.contains(node1)){
                    return false;
                }
                node1=node1.parent;
            }
            i=4;
            while (node2!=null&&i-->0){
                if (set1.contains(node2)){
                    return false;
                }
                node2=node2.parent;
            }
            return true;
        }

        public static Node getNode(String name,String last){
            if (last.charAt(last.length()-1)=='f'){
//                return new Node(true,name,last.substring(0,last.length()-1));
                return new Node(true,name,last);
            }
            if (last.charAt(last.length()-1)=='r'){
                return new Node(true,name,last.substring(0,last.length()-7));
            }
            if (last.charAt(last.length()-1)=='m'){
//                return new Node(false,name,last.substring(0,last.length()-1));
                return new Node(false,name,last);
            }
            if (last.charAt(last.length()-1)=='n'){
                return new Node(false,name,last.substring(0,last.length()-4));
            }
            return new Node(false,name,last+"?");
        }

        public boolean checkNature(String a1, String a2) {
            Node node1 = map.get(a1);
            Node node2=map.get(a2);
            return node2.sex == node1.sex;
        }
    }
    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
